package com.jinmei.web.action;

import com.jinmei.model.User;
import com.jinmei.security.crypto.PasswordManager;
import com.jinmei.service.UserService;
import com.jinmei.utils.JinmeiConsts;
import com.opensymphony.xwork2.ActionContext;

public class PasswordSettingAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private UserService userService;
	
	private String password;

	@Override
	public String execute() throws Exception {
		setUserSessionIdAndUsername();
		return SUCCESS;
	}

	public String changePassWord() throws Exception {
		setUserSessionIdAndUsername();
		User user = (User) ActionContext.getContext().getSession().get(JinmeiConsts.USER);
		setUser_sessionid(user.getSessionid());
		PasswordManager pm = PasswordManager.getInstance();
		userService.updatePwd(user.getId(), pm.encrypt(password));
		return SUCCESS;
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
}
